package com.example.test.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQMessage;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.TextMessage;

@Slf4j
@Component
public class ConsumerListener {

    @JmsListener(destination = "activeMq_queue", containerFactory = "queueListener")
    public void receiveQueue(ActiveMQMessage message) throws JMSException {
        String msg = null;
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            msg = textMessage.getText();
            log.info("queue接收到消息：{}", msg);
            message.acknowledge();
        }
    }

}
